﻿@{
    WebSecurity.RequireAuthenticatedUser();
    Layout = "~/_SiteLayout.cshtml";
    Page.Title = "COURIER PROFILE";
     var pageMode=Page.Mode;
    if(pageMode==null){
        pageMode="0";
    }
    var cp = Page.Courier;
    if(cp==null){
        cp = new Courier();
    }    
}

<style type="text/css">
* { font-family: Verdana; font-size: 96%; }
label { width: 15em; float: left; }
label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
p { clear: both; }
.submit { margin-left: 12em; }
em { font-weight: bold; padding-right: 1em; vertical-align: top; }
</style>

<script>
     $(function(){
              //check page mode if, if mode 1 editModeOn, if 2 editModeOff
             if(@pageMode=='0'){
                saveModeOn();
             } 
             
             if(@pageMode=='1'){
                if(@cp.Active=='1'){
                   $("select#sactive").find("option#Yes").attr("selected", true);
                    
                }else{
                  $("select#sactive").find("option#No").attr("selected", true);
                }
                editModeOn();
             }
            
            
              $("#action").click(function(){
                 var action = $(this).val();
                if(action=="SAVE"){
                    saveCPData();
                }else if(action=="EDIT"){
                    saveModeOn();
                }
               }); 
        
            $("#cancel").click(function(){
                editModeOn();
            });
    

   });

function saveCPData(){
     var data = $("#cp_data_form").serialize();
        $.post("/Maintenance/Services/RefDataService/cpsave",data,function(data){
            if(data[2]==null){
            var ccData = data[0];
        
           
            $("#message").empty();
            $("#scode").val(ccData.Code);
            $("#sname").val(ccData.Name);
            $("#sauthper").val(ccData.AuthContactPerson);
            $("#sauthemail").val(ccData.AuthEmail);
            $("#sactive").val(ccData.Active);
       
           // clearForm("#ccForm");
            //dialogCCSaveMode(createCashCard);
                 //$("#message").html("<p class='message error'>Courier Profile has been saved</p>");
                showMessage("Courier Profile has been saved");
                                  
                }
                else{
                    //$("#message").html("<p class='message error'>Courier Profile may have duplicates</p>");
                  showMessage("Courier Profile may have duplicates");  
                }
    },"json");
    editModeOn();
}




function editModeOn(){
    $('#cpform :input').attr('disabled',true);
    $('#action').val("EDIT");
    $('#cancel').attr('disabled',true);
}


function saveModeOn(){
     $('#cpform :input').attr('disabled',false);
     $('#action').val("SAVE");
    $('#cancel').attr('disabled',false);
}

function showMessage(message){
    $('#message').html("<p class='message info'>"+message+"</p>");
    window.setTimeout(hideMessage,5000);
    
}

function hideMessage(){
    $("#message").empty();
}
</script>
<fieldset class="ui-widget ui-widget-content">
<div id="cpdiv"  method="post"  class="ui-widget" >
    <form id="cp_data_form">
    <div id="message" ></div>
     <input type="hidden" name="mode" id="mode" value="@pageMode"/>
    <input type="hidden" name="cpid" id="cpid" value="@cp.ID"/>    
    <div id="cpform">    
            <p><label for="scode">COURIER CODE </label><input type="text" name="scode" value="@cp.Code"/></p>
            <p><label for="sname">COURIER NAME </label><input type="text" name="sname" value="@cp.Name"/></p>
            <p><label for="sauthper">AUTHORIZED CONTACT PERSON </label><input type="text" name="sauthper" value="@cp.AuthContactPerson"/></p>
            <p><label for="sauthemail">AUTHORIZED EMAIL ADDRESS </label><input type="text" name="sauthemail" value="@cp.AuthEmail"/></p>
            <p><label for="sactive">ACTIVE (Y/N) </label>
            <select name="sactive" id="sactive">
                <option id="Yes" value="1">Y</option>
                <option id="No" value="0">N</option></select></p>
        </div>
            <p><div id="buttons">
            <input type="button" value="SAVE" id="action"/>
            <input type="button" value="CANCEL" id="cancel"/>    
                </div></p>
    </form>
</div>
    </fieldset>